//完成接口连接功能
//$(function() {

	//接口地址
	var sysurl = 'http://localhost:8080/'; 
	var imgurl = 'http://img.dongqil.com/iSports/';
	
	//调试开关
	var debug_switch = true;
	
	/**
	 * 调试打印
	 **/
	function syslog(strlog){
		if(debug_switch){
			console.log(strlog);
		}
	}
	
	/**
	 * 判断设备是否PC端
	 **/
	function deviceName() {
	    var userAgentInfo = navigator.userAgent;
	    var Agents = ["Android", "iPhone",
	        "SymbianOS", "Windows Phone",
	        "iPad", "iPod"];
	    var flag = true;
	    var devname = "unknown";
	    for (var v = 0; v < Agents.length; v++) {
	        if (userAgentInfo.indexOf(Agents[v]) > 0) {
	            flag = false;
	            devname = Agents[v];
	            break;
	        }
	    }
	    if(flag){
	    	devname = "PC";
	    }
	    return devname;
	};
	
	/**
	 * 用户接口访问
	 **/
	function doPost(Interface,info,callback){
		var dstURL = sysurl + Interface;
		//owner.syslog(dstURL + JSON.stringify(info));
		
		//读取本地参数
		var setting = getSettings();
		
		//准备参数
		var param = {
			data:info,
			checkcode:"",
			client:deviceName(),
			type: 1,//0 APP;1 后台
			creator:setting.LoginUser.id,
			ver:sysLocalSettings.version
		};
		eval('param.data.token="1234567890"');
		//param.checkcode = str_hmac_md5(settings.checkcodekey,JSON.stringify(param.data));
		param.checkcode = hex_md5(JSON.stringify(param.data));
		
		syslog(dstURL + JSON.stringify(param));
		
		$.ajax({
		    url: dstURL,
			async: true,
			data: JSON.stringify(param),
			dataType: 'json',//服务器返回json格式数据
			type: 'post',//HTTP请求类型,
			//timeout: 3000,
			contentType: 'application/json;charset=utf-8',	              
			success:function(data){
				//owner.syslog("success");
				//服务器返回响应，根据响应结果，分析是否请求成功；
				if(data.status == 200){
					return callback({
						success:true,
						data : data.data
					});
				}else if(data.status == 400){
					return callback({
						success:false,
						code:data.status,
						desc:data.msg
					});
					
				}else{
					alert(data.msg);
					return callback({
						success:false,
						code:data.status,
						desc:data.msg
					});
				}
			},
			error:function(xhr,type,errorThrown){
				//异常处理；
				alert('服务请求失败');
				return callback({
					success:false,
					desc:'服务请求失败'
				});
			}
			
		});
	};

//})

function GetRequest() {
    var url = location.search; //获取url中"?"符后的字串
    var theRequest = new Object();
    if (url.indexOf("?") != -1) {
        var str = url.substr(1);
        strs = str.split("&");
        for(var i = 0; i < strs.length; i ++) {
        	var name = strs[i].split("=")[0];
        	var value = strs[i].split("=")[1];
            //theRequest[name]=unescape(value);
            theRequest[name]=decodeURI(value);
        }
   }
   return theRequest;
};
